#include "n32l40x.h"

__IO uint32_t LsiFreq     = 40000;

void my_iwdt_feed(void)
{

      /* Reload IWDG counter */
    IWDG_ReloadKey();
}



/*********************
 * 实测 大约20秒复位
 *  
*/
void my_iwdt_init(void)
{
    /* IWDG timeout equal to 250 ms (the timeout may varies due to LSI frequency dispersion) */
    /* Enable write access to IWDG_PR and IWDG_RLR registers */
    IWDG_WriteConfig(IWDG_WRITE_ENABLE);
    /* IWDG counter clock: LSI/32 */
    // IWDG_SetPrescalerDiv(IWDG_PRESCALER_DIV32);
    IWDG_SetPrescalerDiv(IWDG_PRESCALER_DIV256);
    /* Set counter reload value to obtain 250ms IWDG TimeOut.
       Counter Reload Value = 250ms/IWDG counter clock period
                            = 250ms / (LSI/32)
                            = 0.25s / (LsiFreq/32)
                            = LsiFreq/(32 * 4)
                            = LsiFreq/128 */
    // IWDG_CntReload(LsiFreq / 128);
    IWDG_CntReload(LsiFreq);
    /* Reload IWDG counter */
    IWDG_ReloadKey();
    /* Enable IWDG (the LSI oscillator will be enabled by hardware) */
    IWDG_Enable();
}